package com.woniu.service.healthSystem.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.mapper.healthSystem.ManagerMapperGb;
import com.woniu.model.healthSystem.dto.EmployeeDto;
import com.woniu.model.healthSystem.entity.Manager;
import com.woniu.service.healthSystem.IManagerServiceGb;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 账号表 服务实现类
 * </p>
 *
 * @author gb
 * @since 2023-10-19
 */
@Service
public class ManagerServiceImplGb extends ServiceImpl<ManagerMapperGb, Manager> implements IManagerServiceGb {

    @Autowired
    private ManagerMapperGb managerMapperGb;

    @Override
    public Manager login(String accountName, String password) {
        LambdaQueryWrapper<Manager> wrapper = Wrappers.lambdaQuery(Manager.class);
        wrapper.eq(StringUtils.hasLength(accountName),Manager::getAccountName,accountName);
        wrapper.eq(StringUtils.hasLength(password),Manager::getPassword,password);
        return baseMapper.selectOne(wrapper);
    }

    /**
     * 多条件分页查询
     *
     * @param condition
     * @param pageNum
     * @param pageSize
     */
    @Override
    public PageInfo<EmployeeDto> findByPage(Map<String, Object> condition, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<EmployeeDto> list = managerMapperGb.findAll(condition);
        return new PageInfo<>(list);
    }

    /**
     * 添加
     *
     * @param manager
     */
    @Override
    public int addManager(Manager manager) {
          return managerMapperGb.addManager(manager);
    }

    /**
     * 修改
     *
     * @param manager
     */
    @Override
    public int update(Manager manager) {
        return managerMapperGb.update(manager);
    }

    /**
     * 删除
     *
     * @param id
     */
    @Override
    public int deleteById(Long id) {
        return managerMapperGb.deleteById(id);
    }

    /**
     * 查询通过accountId
     *
     * @param accountId
     */
    @Override
    public List<Manager> findByAccountId(Long accountId) {
        return managerMapperGb.findByAccountId(accountId);
    }

}
